Maple Tool1.mws

Maple Tool 1

This tool is designed to be used with Activity 1 in Section 10.3.1.

>    with(plots): with(stats[statplots]):
f:=x->exp(x);

Warning, the name changecoords has been redefined

f := proc (x) options operator, arrow; exp(x) end proc

Here are the first nine Taylor polynomials for the exponential function at x = 0 .

>    P[0]:=x->1;
P[1]:=x->P[0](x)+x;
P[2]:=x->P[1](x)+x^2/2;
P[3]:=x->P[2](x)+x^3/(3!);
P[4]:=x->P[3](x)+x^4/(4!);
P[5]:=x->P[4](x)+x^5/(5!);
P[6]:=x->P[5](x)+x^6/(6!);
P[7]:=x->P[6](x)+x^7/(7!);
P[8]:=x->P[7](x)+x^8/(8!);

P[0] := proc (x) options operator, arrow; 1 end proc

P[1] := proc (x) options operator, arrow; P[0](x)+x end proc

P[2] := proc (x) options operator, arrow; P[1](x)+1/2*x^2 end proc

P[3] := proc (x) options operator, arrow; P[2](x)+x^3/3! end proc

P[4] := proc (x) options operator, arrow; P[3](x)+x^4/4! end proc

P[5] := proc (x) options operator, arrow; P[4](x)+x^5/5! end proc

P[6] := proc (x) options operator, arrow; P[5](x)+x^6/6! end proc

P[7] := proc (x) options operator, arrow; P[6](x)+x^7/7! end proc

P[8] := proc (x) options operator, arrow; P[7](x)+x^8/8! end proc

Now we examine the convergence of the polynomial approximations at a particular point x[0] .  The following code will display a graph of the function f(x) , graphs of the first nine Taylor polynomial approximations P[n](x) , and the first nine Taylor approximations at the particular pont x[0] .

Enter a value of x[0]  between -4  and 4 .

>    x[0]:=3;

x[0] := 3

Below the plot we list the approximating values together with the value of f(x)  and the error in the last approximation.  The viewing window [-a .. a, -b .. b]  may be altered by varying the definitions of the constants a  and b .

>    a:=4; b:=60;
PlotA:=plot(f(x),x=-a..a, thickness=3, color=red, xtickmarks=[-a,-a/2,a/2,a], ytickmarks=[-b,-b/2,b/2,b], view=[-a..a,-b..b]):

>    xdata:=[x[0],x[0],x[0],x[0],x[0],x[0],x[0],x[0],x[0]]:
ydata:=[P[0](x[0]), P[1](x[0]), P[2](x[0]), P[3](x[0]),P[4](x[0]), P[5](x[0]), P[6](x[0]), P[7](x[0]), P[8](x[0])]:
PlotF:=scatterplot(xdata, ydata, color=navy):
PlotG:=plot([P[0](x), P[1](x), P[2](x), P[3](x), P[4](x), P[5](x), P[6](x), P[7](x), P[8](x)], x=-a..a, color=green, xtickmarks=[-a,-a/2,a/2,a], ytickmarks=[-b,-b/2,b/2,b], view=[-a..a,-b..b]):
display(PlotA,PlotF,PlotG);
print(Approximations);
evalf(ydata);

>    print(Actual); evalf(f(x[0]));

>    print(Actual-last_approximation);
evalf(f(x[0])-ydata[9]);

a := 4

b := 60

[Maple Plot]

Approximations

[1., 4., 8.500000000, 13., 16.37500000, 18.40000000, 19.41250000, 19.84642857, 20.00915179]
[1., 4., 8.500000000, 13., 16.37500000, 18.40000000, 19.41250000, 19.84642857, 20.00915179]

Actual

20.08553692

Actual-last_approximation

.7638513e-1

>   

>   

>